//document.write("This File is Still Under construction");

function Main()
{
	alert("You insert the date in format dd-mm-yyyy like: 29-03-2009 \n and this program will tell you the day like Monday!");
	var dd = parseInt(getDay());
	var mm = parseInt(getMonth());
	var yy = parseInt(getYear());
	var date = dd+" - "+mm+" - "+yy; //convert the given date into a string.
	//alert("\n The Date you Entered is: "+date);	
	
	var code = calculate(dd,mm,yy);
	var day = getWeekDay(code);
	
	alert(" On  "+date+"  it's: "+day);
}

function calculate(dd,mm,yy)
{
	alert("\n The Date you Entered is: "+dd+" - "+mm+" - "+yy);
	var n = 0;
	var m = getMonthCode(mm,yy); 
	var y = (yy%100); 
	var x = Math.floor(yy/100);
	
	switch(x)
	{
		case 17: n = Math.floor(dd+m+y+(y/4)+5); //formula for calculating day
				break;
		case 18: n = Math.floor(dd+m+y+(y/4)+3); // if year is in between 1800-1899
				break;
		case 19: n = Math.floor(dd+m+y+(y/4)+1); // if year is in between 1900-1999
				break;
		case 20: n = Math.floor(dd+m+y+(y/4)); // for 2000 - 2099
				break;
		default: alert("Error! ");
				break;
	}
	do
	{
		n = n-7;
	}while(n>7);
	return n;
}

function getMonthCode(mm,yy)
{
	var m = 0;
	switch(mm)
	{
			case 01: m = 06; // Jan
						break;
			case 02: m = 02; // Feb
						break;
			case 03: m = 02; // Mar
						break;
			case 04: m = 05; // Apr
						break;
			case 05: m = 07; // May
						break;
			case 06: m = 03; // Jun
						break;
			case 07: m = 05; // Jul
						break;
			case 8: m = 01; // Aug
						break;
			case 9: m = 04; // Sep
						break;
			case 10: m = 06; // Oct
						break;
			case 11: m = 02; // Nov
						break;
			case 12: m = 04; // Dec
						break;
			default: alert(" Error! ");
						break;
	}
	// Leap year adjustment
	var y = (yy%100);
	if(mm<03)
	{
		if(y%4==0)
		{
			alert(yy+" = Leap year");
			if(mm==1)
				m = 05;
			else
				m = 01;
		}
	}
	return m;
}

function getWeekDay(n)
{
	var s = null;
	switch (n)
	{
		case 0: s = "Sunday"; // code for sunday
			break;
		case 1: s = "Monday";
			break;
		case 2: s = "Tuesday";
			break;
		case 3: s = "Wednesday";
			break;
		case 4: s = "Thurday";
			break;
		case 5: s = "Friday";
			break;
		case 6: s = "Saturday";
			break;
		case 7: s = "Sunday"; //  7, 14, 21... multiples of same number can be possible codes
			break;
		default: alert(" Error! ");
			break;
	}
	return s;
}

function getDay()
{
	var dd = prompt("Please Enter the Day: dd = ");
	while(dd>31||dd<1)
	{
		dd = prompt("Invalid Date! Enter a vaild Day = ");
	}
	return dd;
}

function getMonth()
{
	var mm = prompt("Please Enter the Month: mm = ");
	while(mm<1||mm>12)
	{
		mm =("Invalid Date! Enter a vaild Month = ");
	}
	return mm;
}

function getYear()
{
	var yy = prompt("Please Enter the Year: yyyy = ");
	while(yy<1600||yy>2099)
	{
		yy = prompt(" \n Invalid Date! Enter a vaild Year = ");
	}
	return yy;
}
